<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>LeanCloud</title>
    <link href="https://dn-avoscloud.qbox.me/statics/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
<div class="container">

  <h3>重置密码</h3>
  <hr>

  <form class="form-horizontal form login-form" name="resetform" >
    <!-- <legend>重置密码</legend> -->

    <div class="alert" style="display:none" id="error">
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>

    <div class="form-group">
      <label class="col-sm-2 control-label" for="inputEmail" >新密码</label>
      <div class="col-sm-4">
        <input type="password" id="inputEmail" class="form-control" placeholder="新密码" name="password" required>
      </div>
    </div>

    <div class="form-group">
      <label class="col-sm-2 control-label" for="inputPassword" >重新输入</label>
      <div class="col-sm-4">
        <input type="password" id="inputPassword" class="form-control" placeholder="新密码"  name="password1" required>
      </div>
    </div>

    <div class="form-group">
      <div class="col-sm-offset-2 col-sm-4">
        <button type="button" class="btn btn-default" id="reset">重置</button>
      </div>
    </div>

  </form>




</div><!--end container-->
<script src="https://dn-avoscloud.qbox.me/statics/jquery.min.js"></script>
<script src="https://dn-avoscloud.qbox.me/statics/jquery.jsonp.js"></script>

<script type="text/javascript">
  //获得token
  var token = location.search.match(/token=(\w*)/);
  if(token&&token[1]){
    token = token[1];
  }
  $(function(){
    $("#reset").click(function(){
      var p = $("[name=password]");
      var p1 = $("[name=password1]");
      if(p.val()!=p1.val()){
        $("#error").show();
        $("#error").text("两次输入不一致");//密码输入不一致提示
      }
      if(p.val()&&p1.val()&&p.val()==p1.val()){
        $.jsonp({
          url:"/1/resetPassword/"+token,//如果页面运行在自己的服务器，需要写定一个绝对 URL,类似 "https://api.leancloud.cn/1.1/resetPassword/"
          data:{"password":p.val()},
          callbackParameter: "callback",
          cache: false,
          success:function(result){
            $("#error").show();//成功和失败都会有提示信息, 共用 #error
            if(result.error){
              $("#error").text(result.error);
            }else{
              $("#error").text("密码重置成功");
            }
          },
          error:function(result,text){
            $("#error").text("服务器发生错误");
          }
        });
      }

    });
  });




</script>
  </body>
  </html>
